﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;

namespace CooStationsToolsNew
{
    /// <summary>
    /// ProgressWinOpen.xaml 的交互逻辑
    /// </summary>
    public partial class ProgressWinOpen : Window
    {
        ProjectTools pt = new ProjectTools();
        string fileUrl;

        public ProgressWinOpen(string _theUrl)
        {
            InitializeComponent();
            fileUrl = _theUrl;
            NewTimer();
            OpenNow();
        }
        /// <summary>
        /// 进度条的值
        /// </summary>
        /// <param name="pvalue">进度条的值</param>
        public void ChangeProgressValue(double pvalue)
        {
            proBar.Value = pvalue;
        }

        private void NewTimer()
        {
            System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
            timer1.Interval = 500;
            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Enabled = true;
        }

        void timer1_Tick(object sender, EventArgs e)
        {
            count++;
            ChangeProgressValue(count);
            if (thcopy.IsAlive == false)
            {
                this.Close();
            }
        }
        int count = 0;
        Thread thcopy;


        private void OpenNow()
        {
            thcopy = new Thread(Open);
            thcopy.Start();
        }

        private void Open()
        {
            try
            {
                pt.OpenProject(fileUrl);
                count = 100;
                Thread.Sleep(1000);

                thcopy.Abort();
            }
            catch
            {

            }
        }

    }
}
